<link href="./lcommon/header.css" rel="stylesheet" />
<div class="content lheader" id="headContent">
  <div class="left">
    <a href="./06.html" class="logo">长海招聘</a>
    <div class="addr">
      {{city&&city.name}}
      <a @click="changeCity" href="javascript:void(0)" class="btn-change">[切换城市]</a>
    </div>
    <ul class="menu">
      <li><a href="25.html">招聘</a></li>
    </ul>
  </div>
  <div class="right">
    <div class="operate">
      <a href="./05.html" class="newMessage" v-if="user">消息<i class="number"></i></a>
      <a href="11.html" class="" v-if="user">简历</a>
      <a href="javascript:void(0)" class="btn-down">APP下载
        <div class="down-box">
          <div class="item">
            <img src="images/code1.png" alt="" class="code" />
            <div class="btm">
              <img src="images/ios.png" alt="" class="icon" />IOS
            </div>
          </div>
          <div class="item">
            <img src="images/code2.png" alt="" class="code" />
            <div class="btm">
              <img src="images/android.png" alt="" class="icon" />Android
            </div>
          </div>
        </div>
      </a>
    </div>
    <div class="user" v-if="!token">
      <a @click="link('./01.html')">登录/注册 <img src="images/noUser.png" alt="" class="face" /></a>
    </div>
    <div class="user" v-else-if="user">
      <a href="javascript:void(0)">{{user.name||""}}
        <img :src="user.image||'images/noUser.png'" alt="" class="face" />
        <!-- <img src="images/vip.png" alt="" class="vip"> -->
      </a>
      <ul class="sub-menu-box">
        <li><a href="18.html">个人中心</a></li>
        <li><a href="22.html">我的投递</a></li>
        <li><a @click="logout" href="javascript:void(0)">退出登录</a></li>
      </ul>
    </div>
  </div>

  <div class="area-sel" v-if="showArea">
    <div class="inner">
      <div class="title">
        <div class="l-line"></div>
        <span>选择城市</span>
      </div>
      <el-checkbox-group v-model="checkList">
        <div class="larea-content">
          <div>
            <el-checkbox label="" @click.native="change($event, {id:'', name:'全国'})">全国</el-checkbox>
          </div>
          <div>
            <el-checkbox v-for="(item, i) in region" @click.native="change($event, item)" :label="item.id">{{item.name}}
            </el-checkbox>
          </div>
        </div>
      </el-checkbox-group>
      <div class="lbtns" style="text-align: right;">
        <el-button @click="selCity=undefined;showArea=false">取消</el-button>
        <el-button type="primary" @click="subChangCity">确定</el-button>
      </div>
    </div>
  </div>
</div>
<script src="../js/lcommon.js"></script>
<script src="../js/jquery.nicescroll3.7.6.min.js"></script>
<script>
  $(".number").hide()
  var curUser
  new Vue({
    el: '#headContent',
    data: {
      token: getToken() || '',
      user: undefined,
      code: '',
      region: undefined,
      showArea: false,
      checkList: [],
      selCity: undefined,
      city: undefined
    },
    mounted() {
      var city = localStorage.getItem('cur-city')
      if (city) {
        city = JSON.parse(city)
      } else {
        city = {
          id: '',
          name: '全国'
        }
      }
      this.city = city
      this.checkList = [city.id]
      if(this.token){
        this.getUser()
      }
      indexprepare()
    },
    methods: {
      getUser: function (e, num) {
        var vm = this
        var url = 'person/my/info'
        var p = {}
        request(url, 'GET', '',
          function (res) {
            curUser = res.data.info
            vm.user = res.data.info
          },
          function (err) {
            vm.$message.error(err.message)
          }
        )
      },
      link(url) {
        location.href = url
      },
      logout() {
        sessionStorage.removeItem('token')
        location.href = '01.html'
      },
      getUser: function (e, num) {
        var vm = this
        var url = 'person/my/info'
        var p = {}
        request(
          url,
          'GET',
          JSON.stringify(p),
          function (res) {
            curUser = res.data.info
            vm.user = res.data.info
          },
          function (err) {
            vm.$message.error(err.message)
          }
        )
      },
      changeCity() {
        this.region = region
        this.showArea = true
      },
      subChangCity() {
        if (this.selCity) {
          localStorage.setItem('cur-city', JSON.stringify(this.selCity))
          location.reload()
        }
      },
      change(e, item) {
        if (e.target.type != 'checkbox') {
          return
        }
        this.checkList = []
        if (!$(e.target).is('checked')) {
          this.checkList.push(item.id)
          this.selCity = item
        } else {
          this.selCity = undefined
        }
      }
    }
  })
</script>